Henderson_detrend=function(y,len=7){
	if(len==7){
	Sym=c(-0.05875,0.05874,0.29371,0.41259,0.29371,0.05874,-0.05875)
	Asym3=c(-0.04043, 0.06582, 0.28954, 0.39718, 0.26705, 0.02084,NA)
	Asym2=c(-0.04785, 0.06419, 0.29371, 0.40714, 0.28281,NA,NA)
	Asym1=c(-0.16047, 0.07379, 0.42551, 0.66116,NA,NA,NA)
	weight=rbind(rev(Asym1),rev(Asym2),rev(Asym3),matrix(rep(Sym,length(y)-6),ncol=7,byrow=TRUE), Asym3,Asym2,Asym1)
	new_y=array(NA,length(y)+6)
	new_y[4:(3+length(y))]=y
	smooth.y=array(NA,length(y))
	for(k in 1:length(y)){
			smooth.y[k]=sum(new_y[k:(k+6)]*weight[k,],na.rm=TRUE)
	}	
	return(y-smooth.y)
	}

	if(len==5){
	Sym=c(-0.07343,0.29371,0.55944,0.29371,-0.07343)
	Asym2=c(-0.04419, 0.29121, 0.52522, 0.22776,NA)
	Asym1=c(-0.13181, 0.36713, 0.76467,NA,NA)
	weight=rbind(rev(Asym1),rev(Asym2),matrix(rep(Sym,length(y)-4),ncol=5,byrow=TRUE),
			(Asym2),(Asym1))
	new_y=array(NA,length(y)+4)
	new_y[3:(2+length(y))]=y
	smooth.y=array(NA,length(y))
	for(k in 1:length(y)){
			smooth.y[k]=sum(new_y[k:(k+4)]*weight[k,],na.rm=TRUE)
	}	
	return(y-smooth.y)
	}

}
